

function say() {
    alert("LC:1669. 合并两个链表");
}
say();



var mergeInBetween = function (list1, a, b, list2) {
    var countB = 0
    var pre = null
    while (countB < b) {
        if (pre) {
            pre = pre.next
        } else {
            pre = list1
        }
        countB++
    }

    var moveB = pre.next
    pre.next = null //b断开

    var countA = 0
    var aPre = null

    while (countA < a) {
        if (aPre) {
            aPre = aPre.next
        } else {
            aPre = list1
        }
        countA++
    }

    aPre.next = null //a断开

    //a的尾巴链接list2的头; list2的尾巴链接b的后面

    aPre.next = list2

    var move2 = list2
    while (move2.next) {
        move2 = move2.next
    }
    move2.next = moveB.next

    return list1

};
